<?php
namespace app\admin\model;
use think\Model;
class AuthGroupAccess extends Model
{
	/**
	 * 获取管理员权限列表
	 */
	public function getAllData(){
		// $data = $this->field('u.admin_id,u.user_name,u.email,u.add_time,u.status,aga.group_id,ag.title')
  //           ->alias('aga')->join('tp_admin u ON aga.uid=u.admin_id','RIGHT')->join('tp_auth_group ag ON aga.group_id=ag.id','LEFT')->select();
        $data = db('auth_group_access')->field('u.admin_id,u.user_name,u.email,u.add_time,u.status,aga.group_id,ag.title')->alias('aga')
            ->join(['tp_admin'=>'u'],'aga.uid=u.admin_id','RIGHT')->join(['tp_auth_group'=>'ag'],'aga.group_id=ag.id','LEFT')->select();
        $user_data = $first = array();

        foreach ($data as $k => $v) {
            $first[$v['admin_id']][] = $v['title'];
            $user_data[$v['admin_id']] = $v;
        }

        foreach($user_data as $k => $v){
            foreach($first as $m => $n){
                if($k == $m){
                    $v['title'] = implode('、', $n);
                }
            }
            $v['status'] ? $v['status'] = '正常' : $v['status'] =  '停用' ;
            $user_data[$k] = $v;
        }

		return $user_data;

	}
}